/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package serverClasses;

import commonClasses.Messages.LastItemMsg;
import commonClasses.*;
import commonClasses.Messages.ItemMsg;
import commonClasses.commonInterfaces.HostModelIntf;
import java.util.ArrayList;
import commonClasses.commonInterfaces.ProtocolIntf;

/**
 *
 * @author Pozytywny!
 */
public class ListMsgService {

    private ProtocolIntf _protocol;
    private HostModelIntf _model;

    public ListMsgService(ProtocolIntf protocolIntf) {
        _protocol = protocolIntf;
        _model = protocolIntf.getHostModel();
    }

    public void execute() {
         Utils.write("LIST_MSG_NR");

        /// tylko test
        ArrayList<Item> itemList =
                new ArrayList<Item>();

        itemList.add(
                new Item().setBasic(
                    111,
                    new Price("USD", 1234l),
                    "opis jeden"));
        itemList.add(
                new Item().setBasic(
                    222,
                    new Price("CDU", 5678l),
                    "opis dwa"));
        ///--tylko test

        for (int i = 0; i < itemList.size(); i++) {
            if(i+1<itemList.size()) {
                System.out.println("wysyłam itemMsg");
                try {
                    new ItemMsg(_protocol, itemList.get(i)).send();

                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
            if(i+1==itemList.size()) {

                System.out.println("wysyłam lastItemMsg");
                try {
                    new LastItemMsg(_protocol, itemList.get(i)).send();

                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
